package com.lsw.jgyf.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsw.jgyf.R;
import com.lsw.jgyf.model.PhoneDetailsModel;
import com.lsw.jgyf.ui.base.activity.BaseActivity;
import com.lsw.jgyf.ui.base.activity.TitleBarActivity;
import com.lsw.jgyf.util.GlideUtils;
import com.lsw.ninegridimageview.Image;

import java.io.Serializable;

import butterknife.BindView;

/**
 * Created by lsw on 2018/7/9.
 */

public class PhoneDetailsActivity extends TitleBarActivity<PhoneDetailsPresenter> implements View.OnClickListener, PhoneDetailsContract.View {
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.tv_buy)
    TextView tv_buy;
    private String id;
    @BindView(R.id.tv_pinpai)
    TextView tv_pinpai;
    @BindView(R.id.tv_xinghao)
    TextView tv_xinghao;
    @BindView(R.id.tv_front_camera)
    TextView tv_front_camera;
    @BindView(R.id.tv_back_camera)
    TextView tv_back_camera;
    @BindView(R.id.tv_dianchi)
    TextView tv_dianchi;
    @BindView(R.id.tv_fenbianlv)
    TextView tv_fenbianlv;
    @BindView(R.id.tv_cpu)
    TextView tv_cpu;
    @BindView(R.id.iv_heyueji)
    ImageView iv_heyueji;
    @BindView(R.id.tv_price)
    TextView tv_price;

    @Override
    protected int setContentLayoutView() {
        return R.layout.activity_phone_details;
    }

    @Override
    protected void setActionBarDetail() {

    }

    @Override
    protected void initInjector() {
        mActivityComponent.inject(this);
    }

    @Override
    protected void initEventAndData() {
        id = getIntent().getStringExtra("id");
        mPresenter.getData(id);
        Glide.with(mContext).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531156904988&di=b2fdab81cb33f70ffed05364054aa2b0&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2F14ce36d3d539b600aa58fa9de250352ac65cb702.jpg")
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .placeholder(R.mipmap.muti_default_pic)
                .into(image);
        tv_buy.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_buy:
                if (model != null) {
                    Intent intent = new Intent(mContext, SelectionSpecificationsActivity.class);
                    intent.putExtra("data", model);
                    startActivity(intent);
                }

                break;
        }
    }

    PhoneDetailsModel model;

    @Override
    public void setData(PhoneDetailsModel model) {
        this.model = model;
        if (model != null) {
            GlideUtils.loadImageView(mContext, model.getPhone().getImg_url(), image);
            tv_pinpai.setText(model.getPhone().getBrand_name());
            tv_xinghao.setText(model.getPhone().getName());
            tv_front_camera.setText(model.getPhone().getFront_camera() + "万像素");
            tv_back_camera.setText(model.getPhone().getBack_camera() + "万像素");
            tv_dianchi.setText(model.getPhone().getBattery_capacity());
            tv_fenbianlv.setText(model.getPhone().getResolution_ratio());
            tv_cpu.setText(model.getPhone().getCpu_num());
            if (model.getPhone().getIs_contract() == 1) {
                iv_heyueji.setVisibility(View.VISIBLE);
            } else {
                iv_heyueji.setVisibility(View.INVISIBLE);
            }
            tv_price.setText("¥" + model.getPhone().getPrice());
        }
    }

    @Override
    public void openlogin() {
        OpenLogin();
    }
}
